package interface_layer;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import date_layer.Coordinator;

public class panel_seller extends JPanel implements ActionListener {

	private Coordinator coordinator;
	private JLabel Id;
    private JLabel Image;
    private JLabel Information;
    private JLabel Name;
    private JLabel Position;
    private JTextField id;
    private JButton botonSearch;
    private JButton botonSave;
    private JTextField name;
    private JTextField position;
    private JScrollPane scroll_area;
    private JTextArea show_result_area;

    public panel_seller(Coordinator coordinator)
    {
    	this.coordinator = coordinator;
        initComponents();
    }

    private void initComponents()
    {
        name = new JTextField();
        id = new JTextField();
        position = new JTextField();
        botonSearch = new JButton();
        botonSave = new JButton();
        scroll_area = new JScrollPane();
        show_result_area = new JTextArea();
        Name = new JLabel();
        Information = new JLabel();
        Id = new JLabel();
        Position = new JLabel();
        Image = new JLabel();

        setPreferredSize(new java.awt.Dimension(600, 380));
        setLayout(null);

        add(name);
        name.setBounds(20, 140, 190, 20);
        add(id);
        id.setBounds(20, 190, 190, 20);

        add(position);
        position.setBounds(20, 260, 190, 20);

        botonSearch.setText("Search");
        botonSearch.addActionListener(this);
        add(botonSearch);
        botonSearch.setBounds(20, 340, 75, 23);

        botonSave.setText("Save");
        botonSave.addActionListener(this);
        add(botonSave);
        botonSave.setBounds(140, 340, 70, 23);

        show_result_area.setColumns(20);
        show_result_area.setRows(5);
        scroll_area.setViewportView(show_result_area);

        add(scroll_area);
        scroll_area.setBounds(280, 20, 290, 320);

        Name.setText("Name");
        add(Name);
        Name.setBounds(20, 120, 90, 14);

        Information.setText("Information");
        add(Information);
        Information.setBounds(280, 350, 200, 14);

        Id.setText("Id");
        add(Id);
        Id.setBounds(20, 170, 110, 14);

        Position.setText("Position");
        add(Position);
        Position.setBounds(20, 230, 90, 14);
        add(Image);
        Image.setBounds(20, 20, 250, 90);
        Image.setIcon(new ImageIcon("src\\images\\vendedor.png"));
    }

	
	public void actionPerformed(ActionEvent e) 
	{
		if ( e.getSource() == botonSave)
		{
			if (name.getText().equals("") || id.getText().equals("") || position.getText().equals(""))
			{
				Information.setText("debe llenar todos los campos");
			}
			else
			{
				coordinator.manageSeller(1, name.getText(), id.getText(), position.getText());
			}
		}
		else
		{
			if ( e.getSource() == botonSearch)
			{
				if (name.getText().equals("") && id.getText().equals("") && position.getText().equals("") )
				{
					Information.setText("debe llenar algun campo");
				}
				else
				{
					coordinator.manageSeller(2, name.getText(), id.getText(), position.getText());
				}
			}
		}
		

	}
}
